package org.starter;

import org.springframework.context.annotation.Bean;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.transaction.annotation.AbstractTransactionManagementConfiguration;
import org.springframework.transaction.annotation.AnnotationTransactionAttributeSource;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAttributeSource;
import org.springframework.transaction.interceptor.TransactionInterceptor;

import com.easyaop.api.Arounds;
import com.easyaop.api.pointcut.AnnotationPointcut;
import com.easyaop.api.pointcut.Pointcut;
import com.easyaop.api.spring.FromMethodInterceptor;
import com.easyaop.core.AroundsImpl;

// @Configuration(proxyBeanMethods = false)
public class MyAbstractTransactionManagementConfiguration extends AbstractTransactionManagementConfiguration
{

	@Override
	public void setImportMetadata(AnnotationMetadata importMetadata) {
// importMetadata.getan
		importMetadata.getAnnotationTypes();
		System.out.println(1);
		
	}

	@Bean
	public TransactionAttributeSource transactionAttributeSource() {
		return new AnnotationTransactionAttributeSource(false);
	}

	@Bean
	public TransactionInterceptor transactionInterceptor(TransactionAttributeSource transactionAttributeSource) {
		TransactionInterceptor interceptor = new TransactionInterceptor();
		interceptor.setTransactionAttributeSource(transactionAttributeSource);
		if (this.txManager != null) {
			interceptor.setTransactionManager(this.txManager);
		}
		Arounds arounds = AroundsImpl.getInstance();
		Pointcut pointcut = new AnnotationPointcut("org.my", Transactional.class);
		// arounds.add(pointcut, (target, args, join, method) -> {
		// 	System.out.println(111222);
		// 	return method.call();
		// });
		arounds.add(pointcut, new FromMethodInterceptor(interceptor));
		return interceptor;
	}

}
